package com.cloudcc.mobile.presenter;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.net.ErrorInfo;
import com.cloudcc.cloudframe.net.RequestListener;
import com.cloudcc.mobile.dao.AttendanceEngine;
import com.cloudcc.mobile.dao.impl.AttendanceEngineImpl;
import com.cloudcc.mobile.entity.AttendanceEntity;
import com.cloudcc.mobile.event.AttendanceEventList.AttendanceHomeEvent;
import com.cloudcc.mobile.event.AttendanceEventList.AttendanceListEvent;
import com.cloudcc.mobile.event.AttendanceEventList.CheckResultEvent;

/** 考勤
 * 
* @Description: TODO() 
* @author wangzhiqiang
* @date 2016-3-28 下午3:04:16 
*  
*/
public class AttendancePresenter extends BasePresenter {

	private AttendanceEngine mAttendanceEngine;

	public AttendancePresenter() {
		super();
		mAttendanceEngine = new AttendanceEngineImpl();
	}
	
	
	
	
	
	/** 签到&签退
	 * @param lng  经度
	 * @param lat 纬度
	 * @param type 类型 1是内嵌 2 是外欠
	 * @param position 位置
	 * @param checkType 签到 1 签到 2签退
	 */
	public void check(String lng, String lat,
			String type, String position,int checkType){
		final CheckResultEvent event = new CheckResultEvent();
		String serveiceName ="";
		switch (checkType) {
		case 1:
			serveiceName ="checkin";
			break;
		case 2:
			serveiceName ="checkout";
			break;
		}
		mAttendanceEngine.attendance(serveiceName, lng, lat, type, position, new RequestListener() {
			@Override
			public void onSuccess(Object result) {
				event.setOk(true);
				EventEngine.post(event);
			}
			
			@Override
			public void onFailure(ErrorInfo error) {
				event.setOk(false);
				event.setMessage(error.getErrorMessage());
				EventEngine.post(event);
			}
		});
		
	}
	
	/**查询签到历史
	 * @param pageNum
	 */
	public void queryHistory(int pageNum){
		AttendanceListEvent event =new AttendanceListEvent();
		mAttendanceEngine.getAttendanceHistory(pageNum, event);
	}
	
	/**
	 * 主页数据
	 */
	public void queryHome(){
		AttendanceHomeEvent event = new AttendanceHomeEvent();
		mAttendanceEngine.getAttendanceHome(event);
	}
	
	
	public class AttendanceHomeEntity {
		public CheckLoc checkloc;
		public AttendanceEntity todaycheck;

		public class CheckLoc {
			public int deviation;
			public double lat;
			public double lon;
			public int type;
		}
	}


}
